package com.qj.yantaishan.controller;

import java.util.List;
import com.baomidou.mybatisplus.extension.service.IService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.qj.yantaishan.common.annotation.Log;
import com.qj.yantaishan.common.enums.BusinessType;
import com.qj.yantaishan.domain.ImageText;
import com.qj.yantaishan.service.IImageTextService;
import com.qj.yantaishan.common.core.controller.BaseController;
import com.qj.yantaishan.common.core.domain.AjaxResult;
import com.qj.yantaishan.common.utils.poi.ExcelUtil;
import com.qj.yantaishan.common.core.page.TableDataInfo;

/**
 * 图文Controller
 * 
 * @author qihe
 * @date 2022-07-22
 */
@RestController
@RequestMapping("/yantaishan/ImageText")
public class ImageTextController extends BaseController
{
    private String prefix = "yantaishan/ImageText";

    @Autowired
    private IImageTextService imageTextService;

    @RequiresPermissions("yantaishan:text:view")
    @GetMapping()
    public String text()
    {
        return prefix + "/text";
    }

    /**
     * 查询图文列表
     */
    @RequiresPermissions("yantaishan:text:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ImageText imageText)
    {
        startPage();
        List<ImageText> list = imageTextService.selectImageTextList(imageText);
        return getDataTable(list);
    }

    /**
     * 导出图文列表
     */
    @RequiresPermissions("yantaishan:text:export")
    @Log(title = "图文", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ImageText imageText)
    {
        List<ImageText> list = imageTextService.selectImageTextList(imageText);
        ExcelUtil<ImageText> util = new ExcelUtil<ImageText>(ImageText.class);
        return util.exportExcel(list, "图文数据");
    }

    /**
     * 新增图文
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存图文
     */
    @RequiresPermissions("yantaishan:text:add")
    @Log(title = "图文", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ImageText imageText)
    {
        return toAjax(imageTextService.insertImageText(imageText));
    }

    /**
     * 修改图文
     */
    @RequiresPermissions("yantaishan:text:edit")
    @GetMapping("/edit/{pigcmsId}")
    public String edit(@PathVariable("pigcmsId") Long pigcmsId, ModelMap mmap)
    {
        ImageText imageText = imageTextService.selectImageTextByPigcmsId(pigcmsId);
        mmap.put("imageText", imageText);
        return prefix + "/edit";
    }

    /**
     * 修改保存图文
     */
    @RequiresPermissions("yantaishan:text:edit")
    @Log(title = "图文", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ImageText imageText)
    {
        return toAjax(imageTextService.updateImageText(imageText));
    }

    /**
     * 删除图文
     */
    @RequiresPermissions("yantaishan:text:remove")
    @Log(title = "图文", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(imageTextService.deleteImageTextByPigcmsIds(ids));
    }
}
